package com.mars.module.admin.controller;


import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import com.mars.common.enums.BusinessType;
import com.mars.common.result.R;
import com.mars.common.util.ExcelUtils;
import io.swagger.annotations.Api;
import com.mars.framework.annotation.RateLimiter;
import com.mars.module.admin.entity.SysLostFound;
import com.mars.framework.annotation.Log;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import com.mars.common.response.PageInfo;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import com.mars.module.admin.service.ISysLostFoundService;
import com.mars.module.admin.request.SysLostFoundRequest;

import javax.servlet.http.HttpServletResponse;

/**
 * 失物招领控制层
 *
 * @author mars
 * @date 2024-04-04
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "失物招领接口管理",tags = "2.失物招领接口管理")
@RequestMapping("/admin/sysLostFound" )
public class SysLostFoundController {

    private final ISysLostFoundService iSysLostFoundService;

    /**
     * 分页查询失物招领列表
     */
    @ApiOperation(value = "分页查询失物招领列表")
    @PostMapping("/pageList")
    public R<PageInfo<SysLostFound>> pageList(@RequestBody SysLostFoundRequest sysLostFoundRequest) {
        return R.success(iSysLostFoundService.pageList(sysLostFoundRequest));
    }

    /**
     * 获取失物招领详细信息
     */
    @ApiOperation(value = "获取失物招领详细信息")
    @GetMapping(value = "/query/{id}")
    public R<SysLostFound> detail(@PathVariable("id") Long id) {
        return R.success(iSysLostFoundService.getById(id));
    }

    /**
     * 新增失物招领
     */
    @Log(title = "新增失物招领", businessType = BusinessType.INSERT)
    @RateLimiter
    @ApiOperation(value = "新增失物招领")
    @PostMapping("/add")
    public R<Void> add(@RequestBody SysLostFoundRequest sysLostFoundRequest) {
        iSysLostFoundService.add(sysLostFoundRequest);
        return R.success();
    }

    /**
     * 修改失物招领
     */
    @Log(title = "修改失物招领", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改失物招领")
    @PostMapping("/update")
    public R<Void> edit(@RequestBody SysLostFoundRequest sysLostFoundRequest) {
        iSysLostFoundService.update(sysLostFoundRequest);
        return R.success();
    }

    /**
     * 删除失物招领
     */
    @Log(title = "删除失物招领", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除失物招领")
    @PostMapping("/delete/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        iSysLostFoundService.deleteBatch(Arrays.asList(ids));
        return R.success();
    }

    /**
    * 导出失物招领
    *
    * @param response response
    * @throws IOException IOException
    */
    @PostMapping(value = "/export")
    public void exportExcel(HttpServletResponse response,@RequestBody SysLostFoundRequest sysLostFoundRequest) throws IOException {
        List<SysLostFound> list = iSysLostFoundService.list(sysLostFoundRequest);
        ExcelUtils.exportExcel(list, SysLostFound.class, "失物招领信息", response);
    }
}
